package com.collabscm.md.base.dao.impl;

import java.util.List;

import javax.persistence.Query;

import org.springframework.stereotype.Repository;

import com.collabscm.md.base.dao.PersonDao;
import com.collabscm.md.base.model.Person;
import com.collabscm.md.base.model.User;
import com.collabscm.pf.dao.support.DomainDao;

/**
 * 人员DAO
 *
 * @author Tony
 */
@Repository
public class PersonDaoImpl extends DomainDao<User, Long> implements PersonDao<User, Long> {

	/**
	 * 取出所有人员
	 * @return List <Person>
	 */
	@Override
	public List<Person> queryPerson(int start, int pageSize) {
		Query query = entityManager.createNamedQuery(Person.QUERY_PERSON);
		query.setParameter("status", 2001);//TODO
		query.setFirstResult(start);
		query.setMaxResults(pageSize);
		List<Person> personList = query.getResultList();
		logger.info("返回 personList 大小为 : {}", personList.size());
		if (personList.isEmpty()) {
			logger.debug("系统没有人员!");
			return null;
		} else {
			return personList;
		}
	}

	/**
	 * 得到人员总数
	 * @return 总数
	 */
	@Override
	public Integer getCountPerson() {
		Query query = entityManager.createNamedQuery(Person.COUNT_QUERY_PERSON);
		query.setParameter("status", 2001);//TODO
		return new Integer(query.getSingleResult().toString());
		//return new Integer(this.findNamedQueryCount(Organ.COUNT_ALL_ORGAN + CommonConstants.STATUS_ENABLE) + "");
	}
	
}
